package com.persondemo.videoappliction.ui.vip.presenter;

import com.persondemo.videoappliction.bean.PuShopBean;
import com.persondemo.videoappliction.bean.PutShopTypeBean;
import com.persondemo.videoappliction.bean.UpimgBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.vip.contract.PutShopContract;

import javax.inject.Inject;

import okhttp3.MultipartBody;

public class PutShopPresenter extends BasePresenter<PutShopContract.View> implements PutShopContract.Presenter {
    private BaseApi baseApi;

    @Inject
    public PutShopPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void putshop(String title, String shangquan, String renjun, String phone, String business,
                        String address, String imgs, String type, String device) {
        baseApi.putshops(title, shangquan, renjun, phone, business, address, imgs, type, device)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<PuShopBean>() {
                    @Override
                    public void onSuccess(PuShopBean puShopBean) {
                        mView.loadshop(puShopBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void upimgdata(MultipartBody.Part file) {
        baseApi.upimgdata_pingce(file)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<UpimgBean>() {
                    @Override
                    public void onSuccess(UpimgBean upimgBean) {
                        mView.imgdata(upimgBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void gettype() {
        baseApi.gettype()
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<PutShopTypeBean>() {
                    @Override
                    public void onSuccess(PutShopTypeBean putShopTypeBean) {
                        mView.loadtype(putShopTypeBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
